/*
 * CUpdateAddressRangeAction.java
 *
 * Created on January 13, 2007, 7:12 PM
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.admin.actions;

import org.fpdev.core.data.LegacyDB;
import org.fpdev.core.basenet.BLinkStreet;
import org.fpdev.apps.admin.AdminClient;

/**
 *
 * @author demory
 */
public class EditAddressRangesAction implements ACAction {

  private BLinkStreet link_;
  private int oldFAddrL_,  oldFAddrR_,  oldTAddrL_,  oldTAddrR_,  oldZipL_,  oldZipR_;
  private int newFAddrL_,  newFAddrR_,  newTAddrL_,  newTAddrR_,  newZipL_,  newZipR_;

  /** Creates a new instance of CUpdateAddressRangeAction */
  public EditAddressRangesAction(BLinkStreet link, int fAddrL, int fAddrR, int tAddrL, int tAddrR, int zipL, int zipR) {
    link_ = link;
    newFAddrL_ = fAddrL;
    newFAddrR_ = fAddrR;
    newTAddrL_ = tAddrL;
    newTAddrR_ = tAddrR;
    newZipL_ = zipL;
    newZipR_ = zipR;

    oldFAddrL_ = link.getFAddrL();
    oldFAddrR_ = link.getFAddrR();
    oldTAddrL_ = link.getTAddrL();
    oldTAddrR_ = link.getTAddrR();
    oldZipL_ = link.getZipL();
    oldZipR_ = link.getZipR();

  }

  public String getName() {
    return "Update Address Ranges";
  }

  public void updateDB(LegacyDB db) {
  }

  public boolean undoAction(AdminClient av) {
    link_.setAddressRange(oldFAddrL_, oldFAddrR_, oldTAddrL_, oldTAddrR_);
    link_.setZips(oldZipL_, oldZipR_);
    av.getEngine().getDB().updateAddrRange(link_, oldFAddrL_, oldFAddrR_, oldTAddrL_, oldTAddrR_, oldZipL_, oldZipR_);
    return true;
  }

  public boolean doAction(AdminClient av) {
    link_.setAddressRange(newFAddrL_, newFAddrR_, newTAddrL_, newTAddrR_);
    link_.setZips(newZipL_, newZipR_);
    av.getEngine().getDB().updateAddrRange(link_, newFAddrL_, newFAddrR_, newTAddrL_, newTAddrR_, newZipL_, newZipR_);
    return true;
  }
}
